package com.inibb.app.util.lang;

import com.inibb.app.util.SimpChineseUtil;

public final class ChineseUtil {

	private static TradChineseUtil tc;
	private static SimpChineseUtil sc;
	
	private static TradSimpChineseUtil scts;
	static{
		try {
			tc = TradChineseUtil.getInstance();
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			sc = SimpChineseUtil.getInstance();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		try {
			scts = TradSimpChineseUtil.getInstance();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static boolean isChineseAlphaNumeric(String data){
		return scts.isChineseAlphaNumeric(data);
	}
	public static boolean isChinese(String data){
		return scts.isChinese(data);
	}
	public static boolean isChineseNumeric(String data){
		return scts.isChineseNumeric(data);
	}
	
	public static boolean isTCAlphaNumeric(String data){
		return tc.isTCAlphaNumeric(data);
	}
	public static boolean isTraditionalChinese(String data){
		return tc.isTraditionalChinese(data);
	}
	public static boolean isTraditionalChineseNumeric(String data){
		return tc.isTraditionalChineseNumeric(data);
	}

	public static boolean isSCAlphaNumeric(String data){
		return sc.isSCAlphaNumeric(data);
	}
	public static boolean isSimplifiedChinese(String data){
		return sc.isSimplifiedChinese(data);
	}
	public static boolean isSimplifiedChineseNumeric(String data){
		return sc.isSimplifiedChineseNumeric(data);
	}
	
	public static boolean containSimplifiedChinese(String data){
		String[] datas = StringUtil.tokenize(data, 1);
		if(datas == null || datas.length <= 0){
			return false;
		}
		
		for(String str : datas){
			if(!StringUtil.isEmptyString(str) && sc.isSimplifiedChinese(str)){
				return true;
			}
		}
		return false;
	}
	
	public static boolean containTraditionalChinese(String data){
		String[] datas = StringUtil.tokenize(data, 1);
		if(datas == null || datas.length <= 0){
			return false;
		}
		
		for(String str : datas){
			if(!StringUtil.isEmptyString(str) && tc.isTraditionalChinese(str)){
				return true;
			}
		}
		return false;
	}
	
	public static void main(String[] args){
//		 int[] codePoints = new int[] {0x66fe, 0x8efb, 0x9B43, 0x8BFB, 0x8B80};
//	        
//	     String testString = new String(codePoints, 0, codePoints.length);
//	     
//	     System.out.println(testString);
//	     
//	     System.out.println(isChineseAlphaNumeric(testString));
//	     
//	     System.out.println(isTCAlphaNumeric(testString));
//	     
//	     System.out.println(isSCAlphaNumeric(testString));
	     
	     //System.out.println(containSimplifiedChinese("CHAN MAN MAN1CHAN MAN MAN2"));
	    // System.out.println(isSimplifiedChinese("CHAN MAN MAN1CHAN MAN MAN2"));
		System.out.println(isChinese("ABC"));
		System.out.println(ChineseUtil.isChineseAlphaNumeric("い1�7"));
		System.out.println(ChineseUtil.isChineseAlphaNumeric("テキスト翻訳"));
		System.out.println(ChineseUtil.isChineseAlphaNumeric("あなたはだれ？テキスト翻訳�1�7�Webページや文書"));
		System.out.println(ChineseUtil.isChineseAlphaNumeric("Bạn là ai?"));
		System.out.println(ChineseUtil.isChineseAlphaNumeric("ผูไ1�7 are you?"));
		System.out.println(ChineseUtil.isChineseAlphaNumeric("寧寜"));
		System.out.println(TradChineseUtil.dumpUtf16Hex("寧寜"));
		System.out.println(TradChineseUtil.dumpUtf16Hex("寧寧"));
		System.out.println(TradChineseUtil.dumpUtf16Hex("币簚"));
		System.out.println(ChineseUtil.isChineseAlphaNumeric("簄1�7"));
		System.out.println(ChineseUtil.isChineseAlphaNumeric("叄1�7"));
	}
}
